package _5thread;

import java.util.concurrent.CountDownLatch;

/**
 * @description:
 * @author: wang zhen
 * @create: 2022-06-07 16:30
 */
public class CountDownLatchTest {

    static CountDownLatch countDownLatch=new CountDownLatch(2);

    public static void main(String[] args) throws Exception{

        new Thread(){
            @Override
            public void run() {
                System.out.println("扣减库存成功");
                countDownLatch.countDown();
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                try { Thread.sleep(2000); }catch (Exception e){}

                System.out.println("扣款成功");
                countDownLatch.countDown();
            }
        }.start();


        countDownLatch.await();
        new Thread(){
            @Override
            public void run() {
                System.out.println("返回结果");
            }
        }.start();

    }
}
